import requests,unittest

class A3mall(unittest.TestCase):
    #login 登录
    token=None
    def test_A3mall_01_login(self):
        url='http://10.59.9.14:7003/api/public/login'
        josn={"username":"17733058407","password":"li123456"}

        login=requests.post(url=url,json=josn)
        print(login.json())
        A3mall.token=login.json()['data']['token']
        print(A3mall.token)

    #info 个人中心
    def test_A3mall_02_info(self):
        url='http://10.59.9.14:7003/api/ucenter/info'
        headers={'Auth-Token':'Bearer '+A3mall.token}
        info=requests.get(url=url,headers=headers)
        print(info.json())
    #second 商品列表
    def test_A3mall_03_second(self):
        url='http://10.59.9.14:7003/api/second?page=1&type=0&sort=1'
        headers = {'Auth-Token': 'Bearer ' + A3mall.token}
        second=requests.get(url=url,headers=headers)
        print(second.json())

    #view 商品详情
    def test_A3mall_04_view(self):
        url = 'http://10.59.9.14:7003/api/second/view?id=17'
        headers = {'Auth-Token': 'Bearer ' + A3mall.token}
        view = requests.get(url=url, headers=headers)
        print(view.json())

    #index 支付方式
    def test_A3mall_05_index(self):
        url = 'http://10.59.9.14:7003/api/payment/index'
        josn = {"type":"h5","pay_type":"order"}
        index = requests.post(url=url, json=josn)
        print(index.json())

    #confirm 创建订单
    def test_A3mall_06_confirm(self):
        url = 'http://10.59.9.14:7003/api/order/confirm?id=17&type=second&sku_id=&num=1&shipping_type=1'
        headers = {'Auth-Token': 'Bearer ' + A3mall.token}
        confirm = requests.get(url=url, headers=headers)
        print(confirm.json())

    #create 支付成功
    def test_A3mall_07_create(self):
        url = 'http://10.59.9.14:7003/api/order/create'
        josn = {"id":"17","type":"second","address_id":179,"store_id":"0","shipping_type":1,
                "bonus_id":"0","payment":"balance","remarks":"","source":1,
                "url":"http://10.59.9.14:7003/wap/pages/cart/confirm?id=17&sku_id=&num=1&type=second","sku_id":"","num":"1"}
        headers = {'Auth-Token': 'Bearer ' + A3mall.token}
        create = requests.post(url=url, json=josn,headers=headers)
        print(create.json())

    #detail 查看订单
    def test_A3mall_08_detail(self):
        url = 'http://10.59.9.14:7003/api/order/detail'
        josn = {"id":"154229"}
        headers = {'Auth-Token': 'Bearer ' + A3mall.token}
        detail = requests.post(url=url, json=josn, headers=headers)
        print(detail.json())

    #delivery 确认订单
    def test_A3mall_09_delivery(self):
        url = 'http://10.59.9.14:7003/api/order/delivery'
        josn = {"id": "154229"}
        headers = {'Auth-Token': 'Bearer ' + A3mall.token}
        delivery = requests.post(url=url, json=josn, headers=headers)
        print(delivery.json())

    #confirm_delivery 确认收货
    def test_A3mall_10_confirm_delivery(self):
        url = 'http://10.59.9.14:7003/api/order/confirm_delivery'
        josn = {"id": "154229"}
        headers = {'Auth-Token': 'Bearer ' + A3mall.token}
        delivery = requests.post(url=url, json=josn, headers=headers)
        print(delivery.json())

if __name__ == '__main__':
    unittest.main()